package Collection;

import java.util.*;

/**
 * 排序字符串
 */
public class SortListDemo2 {
    public static void main(String[] args) {
        List<String> list =new ArrayList<>();
        list.add("苍老师是是是是");
        list.add("小泽老师");
        list.add("范老师");
        System.out.println(list);
        //定义一个比较器，按照字多字少排列

//        Collections.sort(list, new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.length()-o2.length();
//            }
//        });
        Collections.sort(list,(o1, o2) ->o1.length()-o2.length());
//        Collections.sort(list,Comparator.comparingInt(String::length));
        System.out.println(list);
    }
}
